

function say() {
    alert("LC:113");
}
say();



/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} targetSum
 * @return {number[][]}
 */
var pathSum = function (root, targetSum) {
    //12:53
    //暴力,找出所有路径,路径求和,跟targetSum比较
    //9:15-30

    var strArr = []
    function strdfs(root, str) {
        if (!root) {
            return
        } else {
            if (!root.left && !root.right) {
                str += root.val
                strArr.push(str)
                str = ''
            }
            str += root.val + '->'
            strdfs(root.left, str)
            strdfs(root.right, str)
        }
    }
    strdfs(root, '')

    return strArr2Arr(strArr,targetSum)
};


function strArr2Arr (strArr, targetSum){
    var res = []
    for(var i = 0; i < strArr.length; i++){
        var str = strArr[i]
        var arr = str.split('->')
        
        var count = 0
        for(var j = 0; j < arr.length; j++){
            count += parseInt(arr[j])
        }

        if(count == targetSum){
            res.push(arr)
        }
    }
    return res
}

